home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / plot.uport < prev    next >
Encoding:
Text File  |  1989-04-08  |  12.5 KB  |  530 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v06i082: plot(1,3,5) for PC/AT graphics library
  4. Organization: Eindhoven University of Technology, The Netherlands
  5. Reply-To: wietse@wzv.UUCP (Wietse Z. Venema)
  6.  
  7. Posting-number: Volume 6, Issue 82
  8. Submitted-by: wietse@wzv.UUCP (Wietse Z. Venema)
  9. Archive-name: plot.uport
  10.  
  11.  
  12. These files implement UNIX plot(1,3,5) clones on top of the
  13. PC/AT graphics library posted recently in comp.sources.unix
  14. (v18i{059..065}, gl_plot/part{01..07} by dtlewis!lewis).
  15.  
  16. libplot.a:    library of plot(3) compatible functions that 
  17.         produce files in plot(5) format.
  18.  
  19. plot:        filter that displays files in plot(5) format
  20.         on a variety of devices (cga, hercules, ega,
  21.         ibm graphics printer, laserjet).
  22.  
  23. This software was tested under Microport System-V/AT. No change
  24. should be required for other PC UNIX versions (except for some
  25. configuration parameters in the Makefile). Porting to non-UNIX
  26. PC environments should be straightforward.
  27.  
  28.         Wietse Venema (wietse@wzv.UUCP).
  29.  
  30. #! /bin/sh
  31. # This is a shell archive.  Remove anything before this line, then unpack
  32. # it by saving it into a file and typing "sh file".  To overwrite existing
  33. # files, type "sh file -c".  You can also feed this as standard input via
  34. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  35. # will see the following message at the end:
  36. #        "End of shell archive."
  37. # Contents:  README Makefile libplot.c plot.1 plot.c testplot.c
  38. # Wrapped by wietse@wzv on Mon Mar 27 21:22:37 1989
  39. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  40. if test -f 'README' -a "${1}" != "-c" ; then 
  41.   echo shar: Will not clobber existing file \"'README'\"
  42. else
  43. echo shar: Extracting \"'README'\" \(1053 characters\)
  44. sed "s/^X//" >'README' <<'END_OF_FILE'
  45. XThese files implement UNIX plot(1,3,5) clones on top of the
  46. XPC/AT graphics library posted recently in comp.sources.unix. 
  47. X(v18i{059..065}, gl_plot/part{01..07} by dtlewis!lewis).
  48. X
  49. Xlibplot.a:    library of plot(3) compatible functions that 
  50. X        produce files in plot(5) format.
  51. X
  52. Xplot:        filter that displays files in plot(5) format
  53. X        on a variety of devices (cga, hercules, ega,
  54. X        ibm graphics printer, laserjet).
  55. X
  56. XOptions to the plot program are of the form -Tdevice, where 
  57. Xdevice is one of the following:
  58. X
  59. X    cga (CGA)    cga adapter, low (high) resolution
  60. X    herc (HERC)    hercules adapter, page 0 (page 1)
  61. X    ega        ega adapter
  62. X    lp        matrix printer
  63. X    lj        laserjet printer
  64. X
  65. XAlternatively, one may specify the output device type with the
  66. XGLMODE environment variable (see the gl graphics library docs).
  67. X
  68. XThis software was tested under Microport System-V/AT. No change
  69. Xshould be required for other PC UNIX versions (except for some
  70. Xconfiguration parameters in the Makefile). Porting to non-UNIX
  71. XPC environments should be straightforward.
  72. X
  73. X        Wietse Venema (wietse@wzv.UUCP).
  74. END_OF_FILE
  75. if test 1053 -ne `wc -c <'README'`; then
  76.     echo shar: \"'README'\" unpacked with wrong size!
  77. fi
  78. # end of 'README'
  79. fi
  80. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  81.   echo shar: Will not clobber existing file \"'Makefile'\"
  82. else
  83. echo shar: Extracting \"'Makefile'\" \(783 characters\)
  84. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  85. X# location of directory with gl source (modes.h)
  86. XGLMODES    = $$HOME/net/gl
  87. X
  88. X# gl library memory model
  89. X# GLMODEL    = -Ml    for Microport System-V/AT
  90. X# GLMODEL    =     for other systems
  91. XGLMODEL    = -Ml
  92. X
  93. X# gl library location
  94. X# GLLIB    = /usr/local/lib/gl.a
  95. XGLLIB    = -L/usr/local/lib -lgl
  96. X
  97. X# end of configurations options
  98. X
  99. XSHELL    = /bin/sh
  100. XCFLAGS    = -g
  101. XFILES    = README Makefile libplot.c plot.1 plot.c testplot.c
  102. X
  103. Xall: plot libplot.a
  104. X
  105. Xplot:    plot.o
  106. X    $(CC) $(GLMODEL) $(CFLAGS) -o plot plot.o $(GLLIB) -lm
  107. X
  108. Xplot.o:    plot.c
  109. X    $(CC) $(GLMODEL) $(CFLAGS) -I$(GLMODES) -c plot.c
  110. X
  111. Xlibplot.a: libplot.o
  112. X    ar rv libplot.a libplot.o
  113. X
  114. Xtestplot: testplot.o libplot.a
  115. X    $(CC) $(CFLAGS) -o testplot testplot.o libplot.a
  116. X
  117. Xshar:    $(FILES)
  118. X    @shar $(FILES)
  119. X
  120. Xclean:
  121. X    rm -f *.o core testplot
  122. X
  123. Xclobber: clean
  124. X    rm -f plot libplot.a
  125. END_OF_FILE
  126. if test 783 -ne `wc -c <'Makefile'`; then
  127.     echo shar: \"'Makefile'\" unpacked with wrong size!
  128. fi
  129. # end of 'Makefile'
  130. fi
  131. if test -f 'libplot.c' -a "${1}" != "-c" ; then 
  132.   echo shar: Will not clobber existing file \"'libplot.c'\"
  133. else
  134. echo shar: Extracting \"'libplot.c'\" \(1301 characters\)
  135. sed "s/^X//" >'libplot.c' <<'END_OF_FILE'
  136. X/*
  137. X * plot(3) clone. Implements the commands described in the the V7 UNIX 
  138. X * manual pages and produces a standard UNIX plotfile. 
  139. X *
  140. X * The resulting plotfile is to be used with the plot(1) command.
  141. X *
  142. X * Author: Wietse Venema (wietse@wzv.UUCP)
  143. X */
  144. X
  145. X#include <stdio.h>
  146. X
  147. X/* some shorthands... */
  148. X
  149. X#define    Write(x)        fwrite((char *) &x, sizeof(x), 1, stdout)
  150. X#define    Write2(a,b)        Write(a); Write(b)
  151. X#define    Write3(a,b,c)        Write2(a,b); Write(c)
  152. X#define    Write4(a,b,c,d)        Write2(a,b); Write2(c,d)
  153. X#define    Write6(a,b,c,d,e,f)    Write4(a,b,c,d); Write2(e,f)
  154. X
  155. Xopenpl()
  156. X{
  157. X#ifndef unix
  158. X    you may have to select binary mode for stdout
  159. X#endif
  160. X}
  161. X
  162. Xmove(x, y)
  163. X{
  164. X    putchar('m');
  165. X    Write2(x, y);
  166. X}
  167. X
  168. Xcont(x, y)
  169. X{
  170. X    putchar('n');
  171. X    Write2(x, y);
  172. X}
  173. X
  174. Xpoint(x, y)
  175. X{
  176. X    putchar('p');
  177. X    Write2(x, y);
  178. X}
  179. X
  180. Xline(x1, y1, x2, y2)
  181. X{
  182. X    putchar('l');
  183. X    Write4(x1, y1, x2, y2);
  184. X}
  185. X
  186. Xlabel(s)
  187. Xchar           *s;
  188. X{
  189. X    putchar('t');
  190. X    fputs(s,stdout);
  191. X    putchar('\0');
  192. X}
  193. X
  194. Xarc(x, y, x0, y0, x1, y1)
  195. X{
  196. X    putchar('a');
  197. X    Write6(x, y, x0, y0, x1, y1);
  198. X}
  199. X
  200. Xcircle(x, y, r)
  201. X{
  202. X    putchar('c');
  203. X    Write3(x, y, r);
  204. X}
  205. X
  206. Xerase()
  207. X{
  208. X    putchar('e');
  209. X}
  210. X
  211. Xlinemod(s)
  212. Xchar           *s;
  213. X{
  214. X    putchar('f');
  215. X    puts(s);
  216. X}
  217. X
  218. Xspace(x0, y0, x1, y1)
  219. X{
  220. X    putchar('s');
  221. X    Write4(x0, y0, x1, y1);
  222. X}
  223. X
  224. Xclosepl()
  225. X{
  226. X    fflush(stdout);
  227. X}
  228. END_OF_FILE
  229. if test 1301 -ne `wc -c <'libplot.c'`; then
  230.     echo shar: \"'libplot.c'\" unpacked with wrong size!
  231. fi
  232. # end of 'libplot.c'
  233. fi
  234. if test -f 'plot.1' -a "${1}" != "-c" ; then 
  235.   echo shar: Will not clobber existing file \"'plot.1'\"
  236. else
  237. echo shar: Extracting \"'plot.1'\" \(997 characters\)
  238. sed "s/^X//" >'plot.1' <<'END_OF_FILE'
  239. X.TH PLOT 1
  240. X.SH NAME
  241. Xplot -\ display plot files on various output devices
  242. X.SH SYNOPSIS
  243. Xplot [-Tdevice]
  244. X.SH DESCRIPTION
  245. X.ad
  246. XThe plot filter emulates the commands described in the
  247. XV7 UNIX Programmers Manual, using routines provided by 
  248. Xthe gl PC/AT-clone graphics library. The following output 
  249. Xdevices may be specified:
  250. X.TP
  251. Xcga
  252. XCGA graphics adapter, low-resolution mode
  253. X.TP
  254. XCGA
  255. XCGA graphics adapter, high-resolution mode
  256. X.TP
  257. Xherc
  258. XHercules graphics adapter, page 0
  259. X.TP
  260. XHERC
  261. XHercules graphics adapter, page 1
  262. X.TP
  263. Xega
  264. XEGA graphics adapter
  265. X.TP
  266. Xlp
  267. XIBM graphics printer
  268. X.TP
  269. Xlj
  270. XLaserJet printer
  271. X.SH ENVIRONMENT
  272. XGLMODE, default output device type
  273. X.SH SEE ALSO
  274. X.nf
  275. X.na
  276. Xplot(1), plot(3), plot(5) in the UNIX Programmers Manual.
  277. Xgl graphics library documentation.
  278. X.SH DIAGNOSTICS
  279. X.ad
  280. XThe plot filter terminates with a diagnostic if it finds
  281. Xunexpected input.
  282. X.SH AUTHOR
  283. X.nf
  284. X.na
  285. XWietse Venema (wietse@wzv.UUCP)
  286. XMathematics and Computing Science,
  287. XEindhoven University of Technology,
  288. XEindhoven, The Netherlands.
  289. X
  290. END_OF_FILE
  291. if test 997 -ne `wc -c <'plot.1'`; then
  292.     echo shar: \"'plot.1'\" unpacked with wrong size!
  293. fi
  294. # end of 'plot.1'
  295. fi
  296. if test -f 'plot.c' -a "${1}" != "-c" ; then 
  297.   echo shar: Will not clobber existing file \"'plot.c'\"
  298. else
  299. echo shar: Extracting \"'plot.c'\" \(3816 characters\)
  300. sed "s/^X//" >'plot.c' <<'END_OF_FILE'
  301. X/*
  302. X * plot(1) clone. This filter implements the commands described in the 
  303. X * V7 UNIX manual pages, using the gl graphics library routines.
  304. X *
  305. X * Author: Wietse Venema (wietse@wzv.UUCP)
  306. X *
  307. X * Options: -Tdevice, where device is one of:
  308. X *
  309. X *    cga (CGA)    cga adapter, low (high) resolution
  310. X *    herc (HERC)    hercules adapter, page 0 (page 1)
  311. X *    ega        ega adapter
  312. X *    lp        matrix printer 
  313. X *    lj        laserjet printer
  314. X *
  315. X * The output device can also be specified with the GLMODE environment
  316. X * variable. See the gl graphics library documentation for details.
  317. X */
  318. X
  319. X#include <stdio.h>
  320. X#include <modes.h>
  321. X
  322. Xstatic void     confirm();
  323. X
  324. X/*
  325. X * If the output device is specified on the command line we pass it on to
  326. X * the gl library routines by setting the GLMODE environment variable...
  327. X */
  328. X
  329. Xstruct Modetab {
  330. X    char           *modename;
  331. X    int             modeval;
  332. X};
  333. X
  334. Xstruct Modetab  modetab[] = {
  335. X    "cga",    CGA_COLOR_MODE,        /* cga lo-res */
  336. X    "CGA",    CGA_HI_RES_MODE,    /* cga hi-res */
  337. X    "herc",    HERC_P0_MODE,        /* hercules page 0 */
  338. X    "HERC",    HERC_P1_MODE,        /* hercules page 1 */
  339. X    "ega",    EGA_COLOR_MODE,        /* ega */
  340. X    "lp",    IBM_PRINTER,        /* matrix printer */
  341. X    "lj",    LJ_PRINTER,        /* laserjet printer */
  342. X    0, 0,
  343. X};
  344. X
  345. X/* various shorthands */
  346. X
  347. X#define    READ(x)            fread((char *) &x, sizeof(x), 1, stdin)
  348. X#define    READ2(a,b)        READ(a); READ(b)
  349. X#define    READ3(a,b,c)        READ2(a,b); READ(c)
  350. X#define    READ4(a,b,c,d)        READ2(a,b); READ2(c,d);
  351. X#define    READ6(a,b,c,d,e,f)    READ4(a,b,c,d); READ2(e,f);
  352. X
  353. X/* 
  354. X * Process the plotfile. The program terminates with a diagnostic
  355. X * in case of unrecognized data.
  356. X */
  357. X
  358. Xmain(argc, argv)
  359. Xint             argc;
  360. Xchar          **argv;
  361. X{
  362. X    register struct Modetab *mp;
  363. X    register int    c;
  364. X    char            buf[BUFSIZ];
  365. X    int             x, y, x0, y0, x1, y1, x2, y2, r, glmode;
  366. X    static char     envstring[] = "GLMODE=xxxxxx";
  367. X
  368. X    /* process command-line arguments */
  369. X
  370. X    while (--argc && *++argv) {
  371. X    if (strncmp(*argv, "-T", 2) == 0) {
  372. X        for (mp = modetab; mp->modename; mp++) {
  373. X        if (strcmp(*argv + 2, mp->modename) == 0) {
  374. X            sprintf(envstring, "GLMODE=%d", glmode = mp->modeval);
  375. X            putenv(envstring);
  376. X        }
  377. X        }
  378. X    } else {
  379. X        fprintf(stderr, "bad argument: %s\n", *argv);
  380. X        exit(1);
  381. X    }
  382. X    }
  383. X
  384. X#ifndef    unix
  385. X    you may have to select binary mode for stdin
  386. X#endif
  387. X
  388. X    /* process the plotfile */
  389. X
  390. X    openpl();
  391. X
  392. X    while ((c = getchar()) != EOF) {
  393. X    switch (c) {
  394. X    case 'm':                /* move */
  395. X        READ2(x, y);
  396. X        move(x, y);
  397. X        break;
  398. X    case 'n':                /* cont */
  399. X        READ2(x, y);
  400. X        cont(x, y);
  401. X        break;
  402. X    case 'p':                /* point */
  403. X        READ2(x, y);
  404. X        point(x, y);
  405. X        break;
  406. X    case 'l':                /* line */
  407. X        READ4(x1, y1, x2, y2);
  408. X        line(x1, y1, x2, y2);
  409. X        break;
  410. X    case 't':                /* label */
  411. X        {
  412. X        register char  *p = buf;
  413. X
  414. X        while ((c = getchar()) != EOF && c)
  415. X            *p++ = c;
  416. X        *p = '\0';
  417. X        label(buf);
  418. X        }
  419. X        break;
  420. X    case 'a':                /* arc */
  421. X        READ6(x, y, x0, y0, x1, y1);
  422. X        arc(x, y, x0, y0, x1, y1);
  423. X        break;
  424. X    case 'c':                /* circle */
  425. X        READ3(x, y, r);
  426. X        circle(x, y, r);
  427. X        break;
  428. X    case 'e':                /* erase */
  429. X        if (glmode <= MAXVIDEO)
  430. X        confirm();
  431. X        erase();
  432. X        break;
  433. X    case 'f':                /* linemod */
  434. X        gets(buf);
  435. X        linemod(buf);
  436. X        break;
  437. X    case 's':                /* space */
  438. X        READ4(x0, y0, x1, y1);
  439. X        space(x0, y0, x1, y1);
  440. X        break;
  441. X    default:                /* corrupt */
  442. X        closepl();
  443. X        fprintf(stderr,"corrupted plotfile -- giving up\n");
  444. X        exit(1);
  445. X        /* NOTREACHED */
  446. X    }
  447. X    }
  448. X
  449. X    if (glmode <= MAXVIDEO)
  450. X    confirm();
  451. X    closepl();
  452. X    exit(0);
  453. X    /* NOTREACHED */
  454. X}
  455. X
  456. X/* give them a chance before erase() or closepl() clobber the screen */
  457. X
  458. Xstatic void     confirm()
  459. X{
  460. X    FILE           *fp;
  461. X    int             c;
  462. X
  463. X    if (fp = fopen("/dev/tty", "r")) {
  464. X    while ((c = getc(fp)) != EOF && c != '\n');
  465. X    fclose(fp);
  466. X    }
  467. X}
  468. END_OF_FILE
  469. if test 3816 -ne `wc -c <'plot.c'`; then
  470.     echo shar: \"'plot.c'\" unpacked with wrong size!
  471. fi
  472. # end of 'plot.c'
  473. fi
  474. if test -f 'testplot.c' -a "${1}" != "-c" ; then 
  475.   echo shar: Will not clobber existing file \"'testplot.c'\"
  476. else
  477. echo shar: Extracting \"'testplot.c'\" \(552 characters\)
  478. sed "s/^X//" >'testplot.c' <<'END_OF_FILE'
  479. X/* test program for the UNIX plot clones */
  480. X
  481. X#define    SIZE    100
  482. X
  483. Xmain()
  484. X{
  485. X    register int    i;
  486. X
  487. X    openpl();
  488. X
  489. X    space(0, 0, SIZE, SIZE);
  490. X
  491. X    circle(SIZE / 4, SIZE / 4, SIZE / 4);
  492. X
  493. X    move(1, SIZE - 1);
  494. X
  495. X    cont(SIZE - 1, 1);
  496. X
  497. X    for (i = 1; i < SIZE; i++)
  498. X    point(i, i);
  499. X
  500. X    arc(SIZE-25, SIZE-25, SIZE-25, SIZE, SIZE, SIZE-25);
  501. X
  502. X    linemod("dotted");
  503. X
  504. X    move(10, SIZE - 1);
  505. X
  506. X    label("Testing");
  507. X
  508. X    line(0, 0, 0, SIZE);
  509. X    line(0, SIZE, SIZE, SIZE);
  510. X    line(SIZE, SIZE, SIZE, 0);
  511. X    line(SIZE, 0, 0, 0);
  512. X
  513. X    closepl();
  514. X
  515. X    exit(0);
  516. X}
  517. END_OF_FILE
  518. if test 552 -ne `wc -c <'testplot.c'`; then
  519.     echo shar: \"'testplot.c'\" unpacked with wrong size!
  520. fi
  521. # end of 'testplot.c'
  522. fi
  523. echo shar: End of shell archive.
  524. exit 0
  525. -- 
  526. work:    wswietse@eutrc3.uucp    | Eindhoven University of Technology
  527. work:    wswietse@heitue5.bitnet    | Mathematics and Computing Science
  528. home:    wietse@wzv.uucp        | 5600 MB Eindhoven, The Netherlands
  529.  
  530.